using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Globalization;

namespace Barbar.MapReport.DataSource.Esri {
  /// <summary>
  /// Record of Shp file
  /// </summary>
  public class ShpRecord {
    private ShpRecordHeader m_Header;
    private ShpShapeType m_ShapeType;
    private object m_Content;
    private int m_Index;

    /// <summary>
    /// Record header info
    /// </summary>
    public ShpRecordHeader Header {
      get { return m_Header; }
    }

    /// <summary>
    /// Type of record
    /// </summary>
    public ShpShapeType ShapeType {
      get { return m_ShapeType; }
    }

    /// <summary>
    /// Content
    /// </summary>
    public object Content {
      get { return m_Content; }
    }

    /// <summary>
    /// Record index [0..NumRecords]
    /// </summary>
    public int Index {
      get { return m_Index; }
    }

    internal ShpRecord(Stream stream, int index) {
      m_Index = index;
      m_Header = new ShpRecordHeader(stream);
      m_ShapeType = (ShpShapeType)ShpUtility.LoadType(stream, ShpByteOrder.LittleEndian, ShpAtomicType.Integer);
      switch (m_ShapeType) {
        case ShpShapeType.Polygon:
        case ShpShapeType.Polyline:
          m_Content = new ShpRecordPolygon(stream);
          break;
        default:
          throw new NotImplementedException(String.Format(CultureInfo.InvariantCulture, "Unknown shape type {0}.", m_ShapeType));
      }
    }
  }
}
